package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 统计分类下的菜品数
     * @param id
     * @return
     */
    @Select("select count(*)from sky_take_out.dish where category_id=#{id}")
    Integer countDishById(Long id);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void save(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    List<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 查询菜品
     * @param id
     * @return
     */
    @Select("select *from sky_take_out.dish where id=#{id}")
    Dish getById(Long id);

    /**
     * 删除菜品
     * @param ids
     */
    void deleteById(List<Long> ids);

    /**
     * 修改菜品基本信息
     * @param dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select *from sky_take_out.dish where category_id=#{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    @Select("select d.* ,c.name categoryName from sky_take_out.dish d right join sky_take_out.category c on c.id=d.category_id where d.category_id=#{categoryId} and d.status=1")
    List<DishVO> getByCategoryIdWithFlavor(Long categoryId);

    /**
     * 查询菜品总览
     * @param status
     * @return
     */
    @Select("select count(*)from sky_take_out.dish where status=#{status}")
    Integer DishOverViewVO(Integer status);



}
